﻿@inject IHttpService _httpService
@inject IDataCacheService _dataCacheService

<MDialog @bind-Value="Dialog"
         Width="800">
    <MDCard>
        <MCardTitle Class="text-h5">
            合并词条
        </MCardTitle>
        <MCardText Class="pb-0">
            合并时会自动迁移关联信息
        </MCardText>
        <MStepper Value="_step" Vertical Elevation="0" Style="box-shadow: none;" Height="@("auto")">
            <MStepperStep Step="1" Complete="_step>1" >
                输入要合并的词条
            </MStepperStep>
            <MStepperContent Step="1">
                @if (Dialog)
                {
                    <InputDataCard Model="Model"  OnFinshInput="OnStart" />
                }
            

            </MStepperContent>
            <MStepperStep Step="2" Complete="_step>2" >
                正在合并词条
            </MStepperStep>
            <MStepperContent Step="2">
                @if (_step == 2)
                {
                    <ProcCard Model="Model" @ref="procCard" />
                }
            </MStepperContent>
            <MStepperStep Step="3" Complete="_step>3" >
                词条合并完成
            </MStepperStep>
            <MStepperContent Step="3">
                <ResultCard Model="Model" OnRetry="OnRetry"/>
            </MStepperContent>
        </MStepper>
    </MDCard>
</MDialog>
@code {
    private int _step = 1;
    bool Dialog { get; set; }

    public List<MergeEntryModel> Model { get; set; } = new List<MergeEntryModel>();
    private IEnumerable<string> EntryItems { get; set; } = new string[1] { "" };


    ProcCard procCard;

    public async Task OnStart()
    {
        _step = 2;
        StateHasChanged();
        if (procCard != null)
        {
            await procCard.Proc();
        }
        _step = 3;
        StateHasChanged();
    }

    public async Task OnRetry()
    {
        _step = 1;
        StateHasChanged();
    }

    public async Task Refresh(bool dialog)
    {
        Dialog = dialog;

        StateHasChanged();
    }
}
